package com.zlm.callable;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * @Author: 郑
 *
 */
public class CallableTest {
    public static void main(String[] args) throws ExecutionException, InterruptedException {

        //new Thread(new FutureTask<>(new MyThread())).start();
        MyThread myThread = new MyThread();
        FutureTask futureTask = new FutureTask(myThread);//辅助类
        new Thread(futureTask).start();
        System.out.println(futureTask.get());//获取返回值，会阻塞
    }
}

class MyThread implements Callable<String> {
    @Override
    public String call() {
        System.out.println("1024");
        return "12345";
    }
}
